﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BattleThis.Core.Battle
{
	[System.Diagnostics.DebuggerDisplay( "Points {Points}, Level {Level}" )]
	public class Experience
	{

		#region Variablen
		#endregion

		#region Properties

		/// <summary>
		/// Gets or sets the points.
		/// </summary>
		/// <value>
		/// The points.
		/// </value>
		public int Points { get; protected set; }

		/// <summary>
		/// Gets or sets the level.
		/// </summary>
		/// <value>
		/// The level.
		/// </value>
		public int Level { get; protected set; }

		#endregion

		#region Methoden

		/// <summary>
		/// Initializes a new instance of the <see cref="Experience"/> class.
		/// </summary>
		public Experience()
		{
			this.Points = 0;
			GetLevel();
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="Experience"/> class.
		/// </summary>
		/// <param name="points">The points.</param>
		public Experience(int points)
		{
			this.Points = 0;
			this.Level = 1;
		}

		/// <summary>
		/// Raises withe the specified points.
		/// </summary>
		/// <param name="points">The points.</param>
		public void Raise( int points )
		{
			this.Points += points;
			GetLevel();
		}

		/// <summary>
		/// Gets the level.
		/// </summary>
		private void GetLevel()
		{
			this.Level = (int)Math.Sqrt( this.Points );
			if( this.Level <= 0 ) this.Level = 1;
		}

		public override string ToString()
		{
			return string.Format( "Level {0}", this.Level);
		}

		#endregion

	}
}